package com.kaohe.service;

import java.util.List;

import javax.crypto.interfaces.PBEKey;
import javax.security.auth.message.callback.PrivateKeyCallback.Request;

import com.kaohe.dao.ProductDao;
import com.kaohe.domain.Category;
import com.kaohe.domain.PageBean;
import com.kaohe.domain.Product;
import com.sun.org.apache.regexp.internal.recompile;

public class ProductService {

	private ProductDao dao=new ProductDao();
	public PageBean<Product> pquery(PageBean<Product> pq) {
		//查询总条数
		int count=dao.Pcount();
		//查询当前页数据
		List<Product> result=dao.pqueery(pq.getStartIndex(),pq.getPageSize());
		//处理分类名称
		CategoryService service=new CategoryService();
		for (Product product : result) {
			//获取cid
			int cid = product.getCid();
			//根据id查询--category
			Category category=service.toUpdateCategory(cid+"");
			//存储
			product.setCategory(category);
		}
		
		//封装
		pq.setResult(result);
		pq.setTotalRecord(count);
		//返回表现层

		return pq;
	}
	//添加
		public void addproduct(Product product) {
			dao.addproduct(product);
		}
	//修改-跳转页面
	public Product toUpdateproduct(String pid) {
		Product product = dao.toUpdateproduct(pid);
		return product;
	}
	//修改-修改数据
	public void update(Product product) {
		dao.update(product);
	}
	
	//删除deProduct
	public void deProduct(String pid) {
		dao.deProduct(pid);
	}
	
	
		

}
